#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

inline char getc() {
    static char buf[1 << 18], *fs, *ft;
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}

#define getc() getchar()

inline int gn() {
    int k = 0, f = 1;
    char c = getc();
    for (; !isdigit(c); c = getc()) if (c == '-') f = -1;
    for (; isdigit(c); c = getc()) k = k * 10 + (c ^ 0x30);
    return k * f;
}

int a[102], b[102], n, dp[2][102], maxa, ans; // LIS: dp[0]       LDS: dp[1]

struct zkw {
    int M, x[102 << 4];
    zkw() {
        M = 1;
        memset(x, 0, sizeof(x));
    }
    void build(int N) {
        for(; M + 1 <= N; M <<= 1);
    }
    void ins(int o, int p) {
        x[o + M] = p;
        for(o = (o + M) >> 1; o; o >>= 1) {
            x[o] = max(x[o << 1 | 1], x[o << 1]);
        }
    }
    int que(int l, int r) {
        int ans = 0;
        for(l += M - 1, r += M + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
            if(~l & 1) ans = max(ans, x[l + 1]);
            if(r & 1) ans = max(ans, x[r - 1]);
        }
        return ans;
    }
}seg[2];


int main() {
#ifndef LOCAL
    freopen("chorus.in","r",stdin);
	freopen("chorus.out","w",stdout);
#endif
    n = gn();
    for (int i = 1, j = n; i <= n; i++, j--)
        maxa = max(b[j] = a[i] = gn(), maxa);
    seg[0].build(maxa);
    seg[1].build(maxa);
    for (int i = 1; i <= n; i++) {
        dp[0][i] = seg[0].que(1, a[i] - 1) + 1;
        seg[0].ins(a[i], dp[0][i]);
    }
    for (int i = n; i >= 1; i--) {
        dp[1][i] = seg[1].que(1, a[i] - 1) + 1;
        seg[1].ins(a[i], dp[1][i]);
    }
    for (int i = 1; i <= n; i++) ans = max(ans, dp[0][i] + dp[1][i] - 1);

    cout << n - ans<< endl;
}
